package com.burst.reptile.modular.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.common.utils.poi.ExcelUtil;
import com.burst.reptile.framework.aspectj.lang.annotation.Log;
import com.burst.reptile.framework.aspectj.lang.enums.BusinessType;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.monitor.entity.SysJobLog;
import com.burst.reptile.modular.monitor.service.ISysJobLogService;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 定时任务调度日志表 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/monitor/jobLog")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysJobLogController extends BaseController {

	private final ISysJobLogService jobLogService;

	/**
	 * 查询定时任务调度日志列表
	 */
	@PreAuthorize("@ss.hasPermi('monitor:joblog:list')")
	@GetMapping("/list")
	public LayuiResult<Object> list(SysJobLog sysJobLog) {
		Page<SysJobLog> page = startPage();
		Page<SysJobLog> list = jobLogService.selectPageJobLogList(page, sysJobLog);
		return LayuiResult.success(list.getTotal(), list.getRecords());
	}

	/**
	 * 导出定时任务调度日志列表
	 */
	@PreAuthorize("@ss.hasPermi('monitor:joblog:export')")
	@Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public Result<Object> export(SysJobLog sysJobLog) {
		List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
		ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
		return util.exportExcel(list, "调度日志");
	}

	/**
	 * 根据调度编号获取详细信息
	 */
	@PreAuthorize("@ss.hasPermi('monitor:joblog:query')")
	@GetMapping(value = "/{configId}")
	public Result<Object> getInfo(@PathVariable Long jobLogId) {
		return Result.success(jobLogService.selectJobLogById(jobLogId));
	}

	/**
	 * 删除定时任务调度日志
	 */
	@PreAuthorize("@ss.hasPermi('monitor:joblog:remove')")
	@Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobLogIds}")
	public Result<Object> remove(@PathVariable Long[] jobLogIds) {
		return Result.success(jobLogService.deleteJobLogByIds(jobLogIds));
	}

	/**
	 * 清空定时任务调度日志
	 */
	@PreAuthorize("@ss.hasPermi('monitor:joblog:remove')")
	@Log(title = "调度日志", businessType = BusinessType.CLEAN)
	@DeleteMapping("/clean")
	public Result<Object> clean() {
		jobLogService.cleanJobLog();
		return SUCCESS;
	}
}
